package array

func Product[T int | float64](slice []T) T {
	var result T = 1
	for _, v := range slice {
		result *= v
	}
	return result
}

func Sum[T int | float64](slice []T) T {
	var result T
	for _, v := range slice {
		result += v
	}
	return result
}

func Avg[T int | float64](slice []T) T {
	var sum T
	for _, v := range slice {
		sum += v
	}

	return sum / T(len(slice))
}

func Min[T int | float64](slice []T) T {
	if len(slice) == 0 {
		return 0
	}
	minValue := slice[0]
	for _, v := range slice {
		if v < minValue {
			minValue = v
		}
	}
	return minValue
}

func Max[T int | float64](slice []T) T {
	if len(slice) == 0 {
		return 0
	}
	maxValue := slice[0]
	for _, v := range slice {
		if v > maxValue {
			maxValue = v
		}
	}
	return maxValue
}
